home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / util / cdity / Yak210src.lha / Yak_2.10_Src / Prefs / main.c < prev    next >
C/C++ Source or Header  |  1995-08-13  |  24KB  |  975 lines

  1. /*
  2.  * Yak version 2.10
  3.  * ----------------
  4.  * [Yak == Yet Another K(?)ommodity
  5.  *
  6.  * There seems to be a profusion of commodities doing this or that.
  7.  * Heres mine, to do what I want it to:
  8.  *
  9.  *      AutoActivate windows (SunMouse)
  10.  *      ClickToFront, ClickToBack, ScreenCycle
  11.  *      Close/Zip/Shrink/Zoom/Turn a window via keyboard.
  12.  *      Bring up a palette on front screen.
  13.  *      Insert date into read-stream.
  14.  *      Produce key-click (like my keyclick program).
  15.  *      Some other things...
  16.  *
  17.  * Martin W. Scott, Gaël Marziou & Philippe Bastiani, 7/94.
  18.  */
  19. #define __USE_SYSBASE 
  20.  
  21. #include <exec/types.h>
  22. #include <exec/libraries.h>
  23. #include <exec/memory.h>
  24. #include <devices/inputevent.h>
  25. #include <diskfont/diskfont.h>
  26. #include <dos/dos.h>
  27. #include <dos/dostags.h>
  28. #include <dos/notify.h>
  29. #include <graphics/displayinfo.h>
  30. #include <libraries/commodities.h>
  31. #include <libraries/reqtools.h>
  32. #include <libraries/locale.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <workbench/workbench.h>
  35. #include <workbench/startup.h>
  36. #include <clib/alib_protos.h>
  37.  
  38. /* MUI */
  39. #ifdef MUI      /* NMC */
  40. #include <libraries/mui.h>
  41. #include <proto/muimaster.h>
  42. #endif          /* NMC */
  43.  
  44. /* BGUI */
  45. #ifdef BGUI     /* NMC */
  46. #include <libraries/bgui.h>
  47. #include <libraries/bgui_macros.h>
  48. #include <proto/bgui.h>
  49. #endif
  50.  
  51. #include <proto/exec.h>
  52. #include <proto/dos.h>
  53. #include <proto/graphics.h>
  54. #include <proto/commodities.h>
  55. #include <proto/diskfont.h>
  56. #include <proto/icon.h>
  57. #include <proto/iffparse.h>
  58. #include <proto/intuition.h>
  59. #include <proto/keymap.h>
  60. #include <proto/layers.h>
  61. #include <proto/locale.h>
  62. #include <proto/reqtools.h>
  63. #include <proto/wb.h>
  64.  
  65. #include <string.h>
  66. #include <stdarg.h>
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69.  
  70. #include "code.h"
  71. #include "yak.h"
  72. #include "Handlers.h"
  73. #include "hotkey_types.h"
  74. #include "icon.h"
  75. #include "gui.h"
  76. #include "Settings.h"
  77. #include "Requesters.h"
  78. #include "Version.h"
  79.  
  80. #include "yak_locale_strings.h"
  81.  
  82. /* local prototypes for main.c */
  83. static void CloseResources(void);
  84. static BOOL OpenResources(void);
  85. static void FreePatterns(void);
  86. static LONG ProcessMsg(void);
  87. static void NotifyNewPrefs(void);
  88. static SAVEDS LONG ASM HandleAppMsg(REG(a0) struct Hook *hook,REG(a2) APTR obj,REG(a1) struct AppMessage **amsg);
  89. void STACKARGS MAIN(char *);
  90.  
  91. LONG (*HandleIDCMP)(void);        /* GadTools */
  92. LONG (*HandleReturnID)(LONG ID);  /* MUI & BGUI */
  93.  
  94. extern struct WBStartup *WBMsg;
  95.  
  96. /*
  97.  *  libraries opened by startup code; basepointers needed by function pragmas
  98.  */
  99.  
  100. #ifdef _DCC
  101. extern struct ExecBase    *SysBase;
  102. extern struct DosLibrary  *DOSBase;
  103.  
  104. struct Library  *CxBase, *DiskfontBase,
  105.                 *IFFParseBase, *KeymapBase;
  106. #endif
  107.  
  108.  
  109.  
  110. BOOL CreateIcons;
  111.  
  112. char *ProgramName=NULL;
  113. char *PrefsFile=NULL;
  114.  
  115. IMPORT char FontName[];
  116. IMPORT int  FontSize;
  117. IMPORT struct TextFont *TextFont;
  118. IMPORT struct TextAttr Attr;    /*NMC*/
  119.  
  120. BYTE            broker_pri;
  121. struct MsgPort *broker_mp=NULL;
  122.  
  123. CxObj          *broker=NULL;
  124.  
  125. extern struct MsgPort *AppMsgPort;
  126. extern ULONG           appsigflag;
  127.  
  128. ULONG           wndsigflag;        /* here for overlay purposes */
  129. ULONG           cxsigflag=0L;
  130. ULONG           invariantsigflag;
  131.  
  132. BOOL NewPrefs=FALSE;
  133.  
  134. static LONG notifysigbit;
  135. static ULONG notifysigflag=0L;
  136. struct NotifyRequest NotifyRequest;
  137.  
  138. BOOL YakIconified=FALSE;
  139.  
  140.  
  141.  
  142. #if defined(GADTOOLS) || defined(BGUI)
  143.  
  144. /*
  145.  * Determine GUI font according to FONT tooltype        NMC
  146.  * Used by both GADTOOLS and BGUI.
  147.  */
  148.  
  149. VOID
  150. ReadFont( char *Name, int *Size)
  151. {
  152.     if (sscanf(TTString("FONT", ""),"%s %d", Name, Size) >= 2)
  153.     {
  154.         if (Name[0] == '"')
  155.         {
  156.             sscanf(TTString("FONT", ""),"\" %s %d", Name, Size);
  157.         }
  158.         strcat(Name, ".font");
  159.     }
  160.     else
  161.     {
  162.         Name[0] = '\0';
  163.         *Size    = 8;
  164.     }
  165. }
  166. #endif
  167.  
  168.  
  169. #ifdef MUI
  170. /*
  171.  *
  172.  *                   MUI Specific Code
  173.  *
  174.  */
  175.  
  176. struct Library *MUIMasterBase;
  177.  
  178. APTR App=NULL;
  179.  
  180. struct Hook AppMsgHook = { { NULL,NULL },(void *)HandleAppMsg,NULL,NULL };
  181.  
  182. /* close what we opened */
  183. static void
  184. CloseResources()
  185. {
  186.         /* NULL pointers are valid so don't waste time to test them */
  187.         CloseLibrary(MUIMasterBase);
  188.         CloseLibrary(CxBase);
  189.         CloseLibrary(DiskfontBase);
  190.         CloseLibrary(IFFParseBase);
  191.         CloseLibrary(KeymapBase);
  192.         CloseLocaleStuff();
  193. }
  194.  
  195.  
  196. /* open libraries, devices that we need */
  197. static BOOL
  198. OpenResources(void)
  199. {
  200.         if ((MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN)) &&
  201.             (CxBase        = OpenLibrary("commodities.library", 37L)) &&
  202.             (DiskfontBase  = OpenLibrary("diskfont.library", 36L)) &&
  203.             (IFFParseBase  = OpenLibrary("iffparse.library", 37L)) &&
  204.             (KeymapBase    = OpenLibrary("keymap.library", 37L)))
  205.         {
  206.                 return TRUE;
  207.         }
  208.         CloseResources();
  209.         return FALSE;
  210. }
  211.  
  212.  
  213. BOOL 
  214. CreateApp(void)
  215. {
  216.     /* Set up the MUI application */
  217.     App = ApplicationObject,
  218.                 MUIA_Application_Author,      AUTHOR,
  219.                 MUIA_Application_Title,       "Yak_Prefs",
  220.                 MUIA_Application_Version,     versionstr,
  221.                 MUIA_Application_Copyright,   COPYRIGHT_STR,
  222.                 MUIA_Application_Description, "Yak Preferences",
  223.                 MUIA_Application_BrokerPri,   (LONG)broker_pri,
  224.                 MUIA_Application_SingleTask,  TRUE,
  225.                 MUIA_Application_Active,      TRUE,
  226.                 End;
  227.  
  228.     if (App)
  229.     {
  230.         DoMethod(App,
  231.                 MUIM_Notify, MUIA_Application_DoubleStart, TRUE,
  232.                 App, 
  233.                 2,
  234.                 MUIM_Application_ReturnID, ID_SHOW
  235.                 );
  236.  
  237.         DoMethod(App,
  238.                 MUIM_Notify,
  239.                 MUIA_Application_Iconified, TRUE,
  240.                 App,
  241.                 2,
  242.                 MUIM_Application_ReturnID, ID_HIDE
  243.                 );
  244.  
  245.         DoMethod(App,
  246.                 MUIM_Notify,
  247.                 MUIA_Application_Iconified, FALSE,
  248.                 App,
  249.                 2,
  250.                 MUIM_Application_ReturnID, ID_SHOW
  251.                 );
  252.  
  253.         get(App, MUIA_Application_BrokerPort, broker_mp);
  254.  
  255.         return TRUE;
  256.     }
  257.  
  258.     return FALSE;
  259. }
  260.  
  261. void
  262. DisposeApp(void)
  263. {
  264.     if (App) MUI_DisposeObject(App);
  265. }
  266.  
  267.  
  268. static LONG
  269. ProcessMsg(void)
  270. {
  271.     BOOL  running=TRUE;
  272.     ULONG signal, sigrcvd;
  273.     LONG  id;
  274.  
  275.     switch (id=DoMethod(App, MUIM_Application_Input, &signal))
  276.     {
  277.         case MUIV_Application_ReturnID_Quit:
  278.                 running = FALSE;
  279.                 break;
  280.  
  281.         case ID_HIDE:
  282.                 YakIconified = TRUE;
  283.                 break;
  284.  
  285.         case ID_SHOW:
  286.                 if (YakIconified)
  287.                 {
  288.                     YakIconified = FALSE;
  289.                     set(App, MUIA_Application_Iconified, FALSE);
  290.                 }
  291.                 if (NewPrefs)
  292.                 {
  293.                     /* Settings have changed */
  294.                     if (GetOrders(getString(Update_Restore_ORDERS),
  295.                                   getString(Prefs_modified_STRING)))
  296.                     {
  297.                         LoadSettings(ENV_CONFIG_FILE);
  298.                         HideInterface();
  299.                         curwinID = ROOT_WINDOW;
  300.                         NewPrefs = FALSE;
  301.                     }
  302.                 }
  303.                 if (!ShowYakInterface())
  304.                 {
  305.                     running = FALSE;
  306.                 }
  307.                 break;
  308.  
  309.         default:
  310.                 if ((id>0) && ((*HandleReturnID)(id) != RET_OKAY))
  311.                     running = FALSE;
  312.                 break;
  313.     }
  314.  
  315.     if (running && signal) 
  316.     {
  317.         sigrcvd = Wait(signal | invariantsigflag);
  318.  
  319.         if (sigrcvd & notifysigflag)
  320.         {
  321.             NotifyNewPrefs();
  322.         }
  323.  
  324.         if (sigrcvd & SIGBREAKF_CTRL_C)
  325.             running = FALSE;
  326.     }
  327.     return running;
  328. }
  329.  
  330.  
  331. #endif          /* MUI */
  332. #ifdef BGUI
  333.  
  334. /*
  335.  *
  336.  *             BGUI Specific Code               NMC
  337.  *
  338.  */
  339.  
  340. struct Library  *BGUIBase;
  341. Object                  *MyCxObj;
  342.  
  343. /* close what we opened */
  344. static void
  345. CloseResources()
  346. {
  347.         /* NULL pointers are valid so don't waste time to test them */
  348.         CloseLibrary((struct Library *)IntuitionBase);
  349.         CloseLibrary((struct Library *)GfxBase);
  350.         CloseLibrary(CxBase);
  351.         CloseLibrary(DiskfontBase);
  352.         CloseLibrary(IconBase);
  353.         CloseLibrary(BGUIBase);
  354.         CloseLibrary(WorkbenchBase);
  355.         CloseLibrary(IFFParseBase);
  356.         CloseLibrary(KeymapBase);
  357.         CloseLocaleStuff();
  358. }
  359.  
  360. /* open libraries, devices that we need */
  361. static BOOL
  362. OpenResources(void)
  363. {
  364.         if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37L)) &&
  365.             (GfxBase       = (struct GfxBase *)OpenLibrary("graphics.library", 37L)) &&
  366.             (CxBase        = OpenLibrary("commodities.library", 37L)) &&
  367.             (DiskfontBase  = OpenLibrary("diskfont.library", 36L)) &&
  368.             (IconBase      = OpenLibrary("icon.library", 37L)) &&
  369.                         (BGUIBase      = OpenLibrary("bgui.library", 38L)) &&
  370.             (WorkbenchBase = OpenLibrary("workbench.library", 37L)) &&
  371.             (IFFParseBase  = OpenLibrary("iffparse.library", 37L)) &&
  372.             (KeymapBase    = OpenLibrary("keymap.library", 37L)))
  373.         {
  374.                 return TRUE;
  375.         }
  376.         CloseResources();
  377.         return FALSE;
  378. }
  379.  
  380. BOOL 
  381. CreateApp(void)
  382. {
  383. if (MyCxObj = CommodityObject,
  384.                 COMM_Name,              "Yak_Prefs",
  385.                 COMM_Title,             VERSION_BROKER,
  386.                 COMM_Description, "Yak Preferences",
  387.                 COMM_Priority,  broker_pri,
  388.                 COMM_Unique,    TRUE,
  389.                 COMM_Notify,    TRUE,
  390.                 COMM_ShowHide,  TRUE,
  391.                 EndObject)
  392.         {
  393.         EnableBroker(MyCxObj);
  394.         GetAttr(COMM_SigMask,MyCxObj,&cxsigflag);
  395.  
  396.         /* if FONT tooltype supplied, open font */
  397.         if (*FontName)
  398.                 {
  399.                 Attr.ta_Name = FontName;
  400.                 Attr.ta_YSize = FontSize;
  401.                 Attr.ta_Style = 0;
  402.                 Attr.ta_Flags = 0;
  403.                 TextFont = OpenDiskFont(&Attr);
  404.                 }
  405.         return(TRUE);
  406.         }
  407. else
  408.         PostError(getString(Allocation_ERR));
  409.  
  410. return(FALSE);
  411. }
  412.  
  413.  
  414. void
  415. DisposeApp(void)
  416. {
  417. DisposeObject(MyCxObj);
  418. if (TextFont) CloseFont(TextFont);
  419. }
  420.  
  421. /* monitor ports, act on messages */
  422. static LONG
  423. ProcessMsg(void)
  424. {
  425.     ULONG sigrcvd, msgid, msgtype,msgdata;
  426.     LONG returnvalue = 1L;
  427.  
  428.         if (curwin)
  429.                 {
  430.                 GetAttr(WINDOW_SigMask,curwinobj,&wndsigflag);
  431.                 GetAttr(WINDOW_AppMask,curwinobj,&appwinsigflag);
  432.                 }
  433.         else
  434.                 wndsigflag = appwinsigflag = 0;
  435.  
  436.     sigrcvd = Wait(invariantsigflag | wndsigflag | appwinsigflag);
  437.  
  438.     if (sigrcvd & appwinsigflag)
  439.     {
  440.         struct AppMessage *amsg;
  441.  
  442.                 while(amsg = GetAppMsg(curwinobj))
  443.         {
  444.             HandleAppMsg(NULL,NULL,&amsg);
  445.  
  446.             ReplyMsg((struct Message *)amsg);
  447.         }
  448.     }
  449.  
  450.     if (sigrcvd & wndsigflag)
  451.                 {
  452.                 while(curwin && ((msgid = HandleEvent(curwinobj)) != WMHI_NOMORE))
  453.                         {
  454.                         if ((*HandleReturnID)(msgid) != RET_OKAY)
  455.                     returnvalue = 0;
  456.                         }
  457.                 }
  458.  
  459.     if (sigrcvd & notifysigflag) /* settings have changed */
  460.     {
  461.         NotifyNewPrefs();
  462.     }
  463.  
  464.  
  465.         while(DoMethod(MyCxObj,CM_MSGINFO,
  466.                 &msgtype,&msgid,&msgdata) != CMMI_NOMORE)
  467.                 {
  468.         switch(msgtype)
  469.         {
  470.           case CXM_COMMAND:
  471.             switch(msgid)
  472.             {
  473.               case CXCMD_UNIQUE:
  474.               case CXCMD_APPEAR:
  475.                 YakIconified = FALSE;
  476.                 if (NewPrefs)
  477.                 {
  478.                     /* Settings have changed */
  479.                     if (GetOrders(getString(Update_Restore_ORDERS),
  480.                                   getString(Prefs_modified_STRING)))
  481.                     {
  482.                         LoadSettings(ENV_CONFIG_FILE);
  483.                         curwinID = ROOT_WINDOW;
  484.                         NewPrefs = FALSE;
  485.                     }
  486.                 }
  487.                 if (!ShowYakInterface())
  488.                 {
  489.                     returnvalue = 0L;
  490.                 }
  491.                 break;
  492.  
  493.               case CXCMD_DISAPPEAR:
  494.                 YakIconified = TRUE;
  495.                 HideInterface();
  496.                 break;
  497.  
  498.               case CXCMD_DISABLE:
  499.                 DisableBroker(MyCxObj);
  500.                 break;
  501.  
  502.               case CXCMD_ENABLE:
  503.                 EnableBroker(MyCxObj);
  504.                 break;
  505.  
  506.               case CXCMD_KILL:
  507.                 returnvalue = 0L;
  508.                 break;
  509.             }
  510.             break;
  511.         }
  512.     }
  513.  
  514.     if (sigrcvd & SIGBREAKF_CTRL_C)
  515.         returnvalue = 0L;
  516.  
  517.  
  518.     return(returnvalue);
  519. }
  520.  
  521.  
  522. #endif                  /* BGUI */
  523. #ifdef GADTOOLS
  524.  
  525. /*
  526.  *
  527.  *             GadTools Specific Code
  528.  *
  529.  */
  530.  
  531. #ifdef _DCC
  532. struct IntuitionBase  *IntuitionBase;
  533. struct GfxBase        *GfxBase;
  534.  
  535. struct Library  *IconBase, *GadToolsBase,
  536.                 *WorkbenchBase;
  537. #endif
  538.  
  539. struct NewBroker newbroker = {
  540.     NB_VERSION,
  541.     "Yak_Prefs",                /* string to identify this broker */
  542.     VERSION_BROKER,
  543.     "Yak Preferences",
  544.     NBU_UNIQUE | NBU_NOTIFY,    /* Don't want any new commodities
  545.                                  * starting with this name.  If someone
  546.                                  * tries it, let me know */
  547.     COF_SHOW_HIDE
  548. };
  549.  
  550.  
  551. /* close what we opened */
  552. static void
  553. CloseResources()
  554. {
  555.         /* NULL pointers are valid so don't waste time to test them */
  556.         CloseLibrary((struct Library *)IntuitionBase);
  557.         CloseLibrary((struct Library *)GfxBase);
  558.         CloseLibrary(CxBase);
  559.         CloseLibrary(DiskfontBase);
  560.         CloseLibrary(IconBase);
  561.         CloseLibrary(GadToolsBase);
  562.         CloseLibrary(WorkbenchBase);
  563.         CloseLibrary(IFFParseBase);
  564.         CloseLibrary(KeymapBase);
  565.         CloseLocaleStuff();
  566. }
  567.  
  568.  
  569. /* open libraries, devices that we need */
  570. static BOOL
  571. OpenResources(void)
  572. {
  573.         if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37L)) &&
  574.             (GfxBase       = (struct GfxBase *)OpenLibrary("graphics.library", 37L)) &&
  575.             (CxBase        = OpenLibrary("commodities.library", 37L)) &&
  576.             (DiskfontBase  = OpenLibrary("diskfont.library", 36L)) &&
  577.             (IconBase      = OpenLibrary("icon.library", 37L)) &&
  578.             (GadToolsBase  = OpenLibrary("gadtools.library", 37L)) &&
  579.             (WorkbenchBase = OpenLibrary("workbench.library", 37L)) &&
  580.             (IFFParseBase  = OpenLibrary("iffparse.library", 37L)) &&
  581.             (KeymapBase    = OpenLibrary("keymap.library", 37L)))
  582.         {
  583.                 return TRUE;
  584.         }
  585.         CloseResources();
  586.         return FALSE;
  587. }
  588.  
  589.  
  590.  
  591. BOOL 
  592. CreateApp(void)
  593. {
  594.     if (broker_mp=CreateMsgPort())
  595.     {
  596.         newbroker.nb_Port = broker_mp;
  597.         cxsigflag = 1L << broker_mp->mp_SigBit;
  598.  
  599.         newbroker.nb_Pri = broker_pri;
  600.  
  601.         if (broker=CxBroker(&newbroker, NULL))
  602.         {
  603.             if ((AppMsgPort=CreateMsgPort()))
  604.             {
  605.                 appsigflag = 1L << AppMsgPort->mp_SigBit;
  606.                 return TRUE;
  607.             }
  608.             else PostError(getString(Allocation_ERR));
  609.         }
  610.     }
  611.     else PostError(getString(Allocation_ERR));
  612.  
  613.     return FALSE;
  614. }
  615.  
  616.  
  617. void
  618. DisposeApp(void)
  619. {
  620.     if (AppMsgPort) DeleteMsgPort(AppMsgPort);
  621.  
  622.     if (broker) DeleteCxObjAll(broker);
  623.             
  624.     if (broker_mp) DeleteMsgPort(broker_mp);
  625. }
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632. /* monitor cx port, act on messages */
  633. static LONG
  634. ProcessMsg(void)
  635. {
  636.     CxMsg *msg;
  637.     ULONG sigrcvd, msgid, msgtype;
  638.     LONG returnvalue = 1L;
  639.  
  640.     sigrcvd = Wait(invariantsigflag | wndsigflag);
  641.  
  642.     if (sigrcvd & appsigflag)
  643.     {
  644.         struct AppMessage *amsg;
  645.  
  646.         while (amsg=(struct AppMessage *)GetMsg(AppMsgPort))
  647.         {
  648.             HandleAppMsg(NULL,NULL,&amsg);
  649.  
  650.             ReplyMsg((struct Message *)amsg);
  651.         }
  652.     }
  653.  
  654.     if (sigrcvd & wndsigflag)
  655.         if ((*HandleIDCMP)() != RET_OKAY)
  656.             returnvalue = 0;
  657.  
  658.     if (sigrcvd & notifysigflag) /* settings have changed */
  659.     {
  660.         NotifyNewPrefs();
  661.     }
  662.  
  663.  
  664.     while(msg = (CxMsg *)GetMsg(broker_mp))
  665.     {
  666.         msgid   = CxMsgID(msg);
  667.         msgtype = CxMsgType(msg);
  668.         ReplyMsg((struct Message *)msg);
  669.  
  670.         switch(msgtype)
  671.         {
  672.           case CXM_COMMAND:
  673.             switch(msgid)
  674.             {
  675.               case CXCMD_UNIQUE:
  676.               case CXCMD_APPEAR:
  677.                 YakIconified = FALSE;
  678.                 if (NewPrefs)
  679.                 {
  680.                     /* Settings have changed */
  681.                     if (GetOrders(getString(Update_Restore_ORDERS),
  682.                                   getString(Prefs_modified_STRING)))
  683.                     {
  684.                         LoadSettings(ENV_CONFIG_FILE);
  685.                         curwinID = ROOT_WINDOW;
  686.                         NewPrefs = FALSE;
  687.                     }
  688.                 }
  689.                 if (!ShowYakInterface())
  690.                 {
  691.                     returnvalue = 0L;
  692.                 }
  693.                 break;
  694.  
  695.               case CXCMD_DISAPPEAR:
  696.                 YakIconified = TRUE;
  697.                 HideInterface();
  698.                 break;
  699.  
  700.               case CXCMD_DISABLE:
  701.                 ActivateCxObj(broker, 0L);
  702.                 break;
  703.  
  704.               case CXCMD_ENABLE:
  705.                 ActivateCxObj(broker, 1L);
  706.                 break;
  707.  
  708.               case CXCMD_KILL:
  709.                 returnvalue = 0L;
  710.                 break;
  711.             }
  712.             break;
  713.         }
  714.     }
  715.  
  716.     if (sigrcvd & SIGBREAKF_CTRL_C)
  717.         returnvalue = 0L;
  718.  
  719.  
  720.     return(returnvalue);
  721. }
  722.  
  723. #endif  /* GADTOOLS */
  724.  
  725. /*
  726.  *
  727.  *             Shared Code
  728.  *
  729.  */
  730.  
  731. static SAVEDS LONG ASM
  732. HandleAppMsg(REG(a0) struct Hook *hook,
  733.              REG(a2) APTR obj,
  734.              REG(a1) struct AppMessage **am)
  735. {
  736.     struct AppMessage *amsg=*am;
  737.  
  738.     if (PrefsFile) FreeVec(PrefsFile);
  739.  
  740.     if (PrefsFile=AllocVec(256, MEMF_CLEAR))
  741.     {
  742.         /* Get first argument */
  743.         struct WBArg *wbarg=amsg->am_ArgList;
  744.  
  745.         if (NameFromLock(wbarg->wa_Lock, PrefsFile, 256))
  746.            AddPart(PrefsFile, wbarg->wa_Name, 256);
  747.     }
  748.  
  749. #ifdef MUI
  750.     if (YakIconified)
  751.     {
  752.         YakIconified = FALSE;
  753.         set(App, MUIA_Application_Iconified, FALSE);
  754.     }
  755. #endif
  756.  
  757.     CloseWindowID(curwinID);
  758.  
  759.     LoadSettings(PrefsFile);
  760.  
  761.     curwinID = ROOT_WINDOW;
  762.     ShowYakInterface();
  763.  
  764.     return 0L;
  765. }
  766.  
  767.  
  768. static void
  769. NotifyNewPrefs(void)
  770. {   
  771.     if (!YakIconified)
  772.     {
  773.         /* GUI is opened */
  774.         DisableYakInterface();
  775.         if (GetOrders(getString(Update_Restore_ORDERS),
  776.                       getString(Prefs_modified_STRING)))
  777.         {
  778.             CloseWindowID(curwinID);
  779.             
  780.             LoadSettings(ENV_CONFIG_FILE);
  781.             
  782.             curwinID = ROOT_WINDOW;
  783.             NewPrefs = FALSE;
  784.             ShowYakInterface();
  785.         }
  786.         else
  787.             EnableYakInterface();
  788.     }
  789.     else
  790.         NewPrefs = TRUE;   /* Yak-Prefs: HIDE mode */
  791. }
  792.  
  793.  
  794. void
  795. EndNotification(void)
  796. {
  797.         EndNotify(&NotifyRequest);
  798.         FreeSignal(notifysigbit);
  799. }
  800.  
  801. void
  802. SetNotification(void)
  803. {
  804.         /* Allocate a signalsbit */
  805.         if ((notifysigbit = AllocSignal(-1L)) != -1)
  806.         {
  807.                 notifysigflag = 1 << notifysigbit;
  808.  
  809.                 /* Initialize notification request */
  810.  
  811.                 NotifyRequest.nr_Name = ENV_CONFIG_FILE;
  812.                 NotifyRequest.nr_Flags = NRF_SEND_SIGNAL; 
  813.                 /* Signal this task */
  814.                 NotifyRequest.nr_stuff.nr_Signal.nr_Task = (struct Task *) FindTask(NULL);
  815.                 /* with this signals bit */
  816.                 NotifyRequest.nr_stuff.nr_Signal.nr_SignalNum = notifysigbit;
  817.  
  818.                 StartNotify(&NotifyRequest);
  819.         }
  820. }
  821.  
  822.  
  823. static void
  824. FreePatterns()
  825. {
  826.         UWORD i;
  827.  
  828.         for (i = 0; i < NUM_PATTERNS; i++)
  829.                 if (patterns[i].pat) FreeVec(patterns[i].pat);
  830. }
  831.  
  832.  
  833. #ifdef _DCC
  834. void _waitwbmsg(void);
  835. static void
  836. uncalled(void)
  837. {
  838.     _waitwbmsg();
  839. }
  840. #endif
  841.  
  842. void 
  843. #ifdef FORTIFY
  844. main(int argc, char **argv)
  845. #else
  846. STACKARGS MAIN(char *arg)             /* Yak: multi-function commodity */
  847. #endif
  848. {
  849. #ifdef FORTIFY
  850.     Fortify_EnterScope();
  851.     Fortify_CheckAllMemory();
  852. #endif
  853.  
  854.     if (OpenResources())
  855.     {
  856.         if (WBMsg)              /* WB Startup */
  857.         {
  858.             struct WBArg *wbarg=&WBMsg->sm_ArgList[WBMsg->sm_NumArgs-1];
  859.  
  860.             if (WBMsg->sm_NumArgs > 1)
  861.             {
  862.                 BPTR dirlock;
  863.  
  864.                 /* Go to icon directory */
  865.                 dirlock = CurrentDir(wbarg->wa_Lock);
  866.  
  867.                 /* Install prefs */
  868.                 CopyFile(wbarg->wa_Name, ENV_CONFIG_FILE);
  869.  
  870.                 /* Go back and exit... */
  871.                 CurrentDir(dirlock);
  872.                 FreeOurIcon();
  873.                 CloseResources();
  874.                 return;
  875.             }
  876.             else
  877.             {
  878.                 /* Get Program Name */
  879.                 if (ProgramName=AllocVec(256, MEMF_CLEAR))
  880.                 {
  881.                     if (NameFromLock(wbarg->wa_Lock, ProgramName, 256))
  882.                         AddPart(ProgramName, wbarg->wa_Name, 256);
  883.                 }
  884.             }
  885.         }
  886.         else                    /* CLI Startup */
  887.         {
  888.             /* Get Program Name */
  889.             if (ProgramName=AllocVec(256, MEMF_CLEAR))
  890.             {
  891.                 BPTR lock;
  892.                 GetProgramName(ProgramName, 256);
  893.                 if (lock=Lock(ProgramName, ACCESS_READ))
  894.                 {
  895.                     NameFromLock(lock, ProgramName, 256);
  896.                     UnLock(lock);
  897.                 }
  898.             }
  899.         }
  900.  
  901.         /* */
  902.         if (PrefsFile=AllocVec(256, MEMF_CLEAR))
  903.         {
  904.             BPTR lock=GetProgramDir();
  905.             if (NameFromLock(lock, PrefsFile, 256))
  906.                 AddPart(PrefsFile, "Presets/", 256);
  907.         }
  908.  
  909.         /* process tool-types */
  910.         GetOurIcon(ProgramName);
  911.  
  912.         /* Open the right locale if tooltype LANGUAGE is used */
  913.         OpenLocaleStuff(TTString("LANGUAGE",NULL));
  914.  
  915. #if defined(GADTOOLS) || defined(BGUI)
  916.         ReadFont( FontName, &FontSize);
  917. #endif
  918.  
  919.         CreateIcons  = TTBool("CREATEICONS", TRUE);
  920.  
  921.         broker_pri = (BYTE)TTInt("CX_PRIORITY", 0);
  922.  
  923.         FreeOurIcon();
  924.  
  925.         if (CreateApp())
  926.         {
  927.             InitYakHotKeyList();
  928.  
  929.             LoadSettings(ENV_CONFIG_FILE);
  930.  
  931. #ifdef GADTOOLS
  932.             ActivateCxObj(broker, 1L);
  933. #endif
  934.             /*
  935.              * We want to be notified each time either
  936.              * ENV:yak.prefs is modified (by Yak Preferences)
  937.              */
  938.             SetNotification();
  939.  
  940.             /* these are the signals waited for, + window sig */
  941.             invariantsigflag = SIGBREAKF_CTRL_C | cxsigflag | appsigflag | notifysigflag;
  942.  
  943.             if (ShowYakInterface())
  944.             {
  945.                 while (ProcessMsg())
  946.                     ;
  947.  
  948.                 HideInterface();
  949.             }
  950.  
  951.             DeleteYakHotKeyList();
  952.  
  953.             EndNotification();
  954.  
  955.             FreePatterns();
  956.  
  957.             CleanMouseCycling();
  958.         }
  959.  
  960.         DisposeApp();
  961.  
  962.         if (ProgramName) FreeVec(ProgramName);
  963.         if (PrefsFile)   FreeVec(PrefsFile);
  964.  
  965. #ifdef FORTIFY
  966.                 Fortify_LeaveScope();
  967. #endif
  968.  
  969.         CloseResources();
  970.     }
  971.     else PostError(getString(Resource_ERR));
  972.  
  973. }
  974.  
  975.